﻿// 自定义加载图集，用于ab包内加载，需要关闭inculdeInbuild

using System;
using UnityEngine;
using UnityEngine.U2D;

namespace XProject
{
 
    public class AtlasLoader : MonoBehaviour
    {
        
        public static event Action<string, Action<SpriteAtlas>> atlasRequested;


        private void OnEnable()
        {
            //注册事件
            SpriteAtlasManager.atlasRequested += RequestAtlas;
        }
        private void OnDisable()
        {
            //注销事件
            SpriteAtlasManager.atlasRequested -= RequestAtlas;
        }


        private void RequestAtlas(string atlasName, Action<SpriteAtlas> callback)
        {
            var sa = ResSys.LoadSpriteAtlas("SpriteAtlas/" + atlasName);
            callback(sa);
        }
    }

}
